package com.ruoyi.web.wrapper;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.ruoyi.common.wrapper.BaseControllerWrapper;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

public class MemberSourceInfoWrapper extends BaseControllerWrapper {

    public MemberSourceInfoWrapper(Map<String, Object> single) {
        super(single);
    }

    public MemberSourceInfoWrapper(List<Map<String, Object>> multi) {
        super(multi);
    }

    private List<String> filedNameList =  Arrays.asList("house", "loanAmount", "car", "gjj", "shebao", "baoxian", "zhima",
                    "huabei", "weili", "baitiao", "yuqi", "xueli", "gongzuo", "xinyongka", "loanTime", "shouru", "yongtu");

    private Map<String, String> sourceDictMap;

    public MemberSourceInfoWrapper setSourceDictMap(Map<String, String> sourceDictMap) {
        this.sourceDictMap = sourceDictMap;
        return this;
    }

    @Override
    public void wrapTheMap(Map<String, Object> map) {

        try {

            Long uid = (Long) map.get("uid");
            if (ObjectUtil.isNotEmpty(uid)){
                map.put("uid", uid+"");
            }

            if (ObjectUtil.isNotEmpty(sourceDictMap)){
                for (String filedName : filedNameList) {
                    String value = (String)map.get(filedName);
                    String filedValue = sourceDictMap.get(value);
                    map.put(filedName, StrUtil.isEmpty(filedValue)?filedName:filedValue);
                }
            }

        }catch (Exception ex){
            ex.printStackTrace();
        }
    }
}
